package com.example.demo4.Controller;

import com.example.demo4.Entity.UserEntity;
import com.example.demo4.Jpa.UserJpa;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author ml
 * @create 2017-05-22--14:34
 */
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserJpa userJpa;

    /**
     * 查询所有列表
     * @return
     */
    @RequestMapping(value = "/list",method = RequestMethod.GET)
    public List<UserEntity> list(){
        return userJpa.findAll();
    }

    /**
     * 保存，更新
     * 主键有值则更新 没有则保存
     * @return
     */
    @RequestMapping(value = "/save",method = RequestMethod.GET)
    public UserEntity save(UserEntity entity){
        return userJpa.save(entity);

    }

    /**
     * 删除
     * @return
     */
    @RequestMapping(value = "/delete",method = RequestMethod.GET)
    public List<UserEntity> delete(Long id){
        userJpa.delete(id);
        return userJpa.findAll();

    }

}
